package com.qf.oa_system.service.impl;

import com.qf.oa_system.entity.Leaves;
import com.qf.oa_system.mapper.LeavesDao;
import com.qf.oa_system.service.LeavesService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * ???ٱ(Leaves)表服务实现类
 *
 * @author makejava
 * @since 2020-06-03 20:26:23
 */
@Service("leavesService")
public class LeavesServiceImpl implements LeavesService {
    @Resource
    private LeavesDao leavesDao;

    @Override
    public List<Leaves> getStuLeaves() {
        return leavesDao.getStuLeaves();
    }

    @Override
    public List<Leaves> getLeaves() {
        return leavesDao.getLeaves();
    }

    /**
     * 通过ID查询单条数据
     *
     * @param leaveId 主键
     * @return 实例对象
     */
    @Override
    public Leaves queryById(Integer leaveId) {
        return this.leavesDao.queryById(leaveId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<Leaves> queryAllByLimit(int offset, int limit) {
        return this.leavesDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param leaves 实例对象
     * @return 实例对象
     */
    @Override
    public Leaves insert(Leaves leaves) {
        this.leavesDao.insert(leaves);
        return leaves;
    }

    /**
     * 修改数据
     *
     * @param leaves 实例对象
     * @return 实例对象
     */
    @Override
    public Leaves update(Leaves leaves) {
        this.leavesDao.update(leaves);
        return this.queryById(leaves.getLeaveId());
    }

    /**
     * 通过主键删除数据
     *
     * @param leaveId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer leaveId) {
        return this.leavesDao.deleteById(leaveId) > 0;
    }

    @Override
    public void agreement(int leaveId) {
        leavesDao.agreement(leaveId);
    }

    @Override
    public void agree(int leaveId) {
        leavesDao.agree(leaveId);
    }

    @Override
    public void teacherLeave(Leaves leaves) {
        System.out.println(leaves);
        leavesDao.teacherLeave(leaves);
    }
}